<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Jhin" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />






<meta name="description" content="ThinkPHP 3.2 令牌验证前言
世上无难事，只要肯放弃。">
<meta property="og:type" content="article">
<meta property="og:title" content="ThinkPHP 3.2 令牌验证">
<meta property="og:url" content="http://jhin.oschina.io/ThinkPHP-DOC/2016-10-21-ThinkPHP 3.2 令牌验证.html">
<meta property="og:site_name" content="Jhin">
<meta property="og:description" content="ThinkPHP 3.2 令牌验证前言
世上无难事，只要肯放弃。">
<meta property="og:updated_time" content="2016-12-22T01:33:22.232Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ThinkPHP 3.2 令牌验证">
<meta name="twitter:description" content="ThinkPHP 3.2 令牌验证前言
世上无难事，只要肯放弃。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://jhin.oschina.io/ThinkPHP-DOC/2016-10-21-ThinkPHP 3.2 令牌验证.html"/>


  <title> ThinkPHP 3.2 令牌验证 | Jhin </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Jhin</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Jhin(ijhin@sina.com)</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-thinkphp">
          <a href="/categories/ThinkPHP-DOC" rel="section">
            
            ThinkPHP
          </a>
        </li>
      
        
        <li class="menu-item menu-item-mysql">
          <a href="/categories/MySQL" rel="section">
            
            MySQL
          </a>
        </li>
      
        
        <li class="menu-item menu-item-php">
          <a href="/categories/PHP" rel="section">
            
            PHP
          </a>
        </li>
      
        
        <li class="menu-item menu-item-linux">
          <a href="/categories/Linux" rel="section">
            
            Linux
          </a>
        </li>
      
        
        <li class="menu-item menu-item-nginx">
          <a href="/categories/Nginx" rel="section">
            
            Nginx
          </a>
        </li>
      
        
        <li class="menu-item menu-item-html">
          <a href="/categories/HTML" rel="section">
            
            HTML5
          </a>
        </li>
      
        
        <li class="menu-item menu-item-javascript">
          <a href="/categories/JavaScript" rel="section">
            
            JavaScript
          </a>
        </li>
      
        
        <li class="menu-item menu-item-onex">
          <a href="/categories/ONEX" rel="section">
            
            ONEX
          </a>
        </li>
      
        
        <li class="menu-item menu-item-yii">
          <a href="/categories/Yii2" rel="section">
            
            Yii2
          </a>
        </li>
      
        
        <li class="menu-item menu-item-shopex">
          <a href="/categories/ShopEX" rel="section">
            
            ShopEX
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                ThinkPHP 3.2 令牌验证
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-10-21T14:51:55+08:00" content="2016-10-21">
              2016-10-21
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/ThinkPHP-DOC/" itemprop="url" rel="index">
                    <span itemprop="name">ThinkPHP</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="ThinkPHP-3-2-令牌验证"><a href="#ThinkPHP-3-2-令牌验证" class="headerlink" title="ThinkPHP 3.2 令牌验证"></a>ThinkPHP 3.2 令牌验证</h3><h4 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h4><blockquote>
<p>世上无难事，只要肯放弃。</p>
</blockquote>
<a id="more"></a>
<h4 id="问题一：-模型加载不正确"><a href="#问题一：-模型加载不正确" class="headerlink" title="问题一： 模型加载不正确"></a>问题一： 模型加载不正确</h4><p>Q：Thinkphp：xxx 方法加载不正确</p>
<p>A：如果使用D 方法，又采用的模块分组的形式。这时候实例化一个分组可以使用：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$User = D(<span class="string">'User'</span>);</div></pre></td></tr></table></figure>
<p>或者：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$User = D(<span class="string">'Admin/User'</span>);</div></pre></td></tr></table></figure>
<p>注：</p>
<p>这里 User 对应的是 在/Admin/Model/User.class.php</p>
<h4 id="问题二：表单验证不正确"><a href="#问题二：表单验证不正确" class="headerlink" title="问题二：表单验证不正确"></a>问题二：表单验证不正确</h4><p>Q：使用create方法后，表单验证不正确，且 SESSION中也没有 <code>__hash__</code> 这个字段的值</p>
<p>A：既然验证不过去，那就关掉吧！</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">C(<span class="string">'TOKEN_ON'</span>,<span class="keyword">false</span>);</div></pre></td></tr></table></figure>
<p>放到create方法前面，就可以了！或者去配置文件中，关掉令牌。</p>
<h4 id="问题三：Create方法不是自动完成"><a href="#问题三：Create方法不是自动完成" class="headerlink" title="问题三：Create方法不是自动完成"></a>问题三：Create方法不是自动完成</h4><p>Q：create 方法不能写入数据库</p>
<p>A：对，这种是对的，create是自动验证模型中的规则，自动完成是另外一个方法，add</p>
<p>使用方法：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$User-&gt;add();</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/ShopEX/2016-10-21-14.ONex B2B2C 二次开发之cookie在挂件中的使用.html" rel="next" title="ONex B2B2C 二次开发 cookie在挂件中的使用">
                <i class="fa fa-chevron-left"></i> ONex B2B2C 二次开发 cookie在挂件中的使用
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/ShopEX/2016-10-21-18.ONex B2B2C 二次开发之报错解决方案.html" rel="prev" title="ONex B2B2C 二次开发 报错解决方案">
                ONex B2B2C 二次开发 报错解决方案 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Jhin" />
          <p class="site-author-name" itemprop="name">Jhin</p>
          <p class="site-description motion-element" itemprop="description">Jhin 开发文档小结</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">22</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#ThinkPHP-3-2-令牌验证"><span class="nav-number">1.</span> <span class="nav-text">ThinkPHP 3.2 令牌验证</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#前言"><span class="nav-number">1.1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#问题一：-模型加载不正确"><span class="nav-number">1.2.</span> <span class="nav-text">问题一： 模型加载不正确</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#问题二：表单验证不正确"><span class="nav-number">1.3.</span> <span class="nav-text">问题二：表单验证不正确</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#问题三：Create方法不是自动完成"><span class="nav-number">1.4.</span> <span class="nav-text">问题三：Create方法不是自动完成</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Jhin</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="/">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="/">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  



  




  
  

  

  

  

  


</body>
</html>
